package com.zat.mes.andrmes.dofun.main.adapter

import android.text.TextUtils
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.BindMachineBean

/**
 * @author zy
 * @date :2020-07-14 18:12
 * @description:绑定设备
 */
class BindMachineAdapter(layoutResId: Int, unbindListener: UnbindListener) :
    BaseQuickAdapter<BindMachineBean, BaseViewHolder>(layoutResId) {
    val unbindListener = unbindListener
    override fun convert(helper: BaseViewHolder, item: BindMachineBean) {
        if (TextUtils.isEmpty(item?.macName)){
            item?.macName= ""
        }
        if(TextUtils.isEmpty(item?.macNo)){
            item?.macNo = ""
        }
        if (TextUtils.isEmpty(item?.model)){
            item?.model = ""
        }
        helper.setText(R.id.tvMachineNameBind, item?.macName)
            .setText(R.id.tvNoBind, "设备编码："+item?.macNo)
            .setText(R.id.tvModelBind, "规格型号："+item?.model)
            .setText(R.id.tvDateBind, "绑定时间："+item?.bingTime)

        val tvClass = helper.getView<TextView>(R.id.tvClassBind)
        if (!TextUtils.isEmpty(item?.className)) {
            tvClass.visibility = View.VISIBLE
            tvClass.text = item?.className
        }else{
            tvClass.visibility = View.GONE
        }
         helper.getView<TextView>(R.id.btnUnbind).setOnClickListener{
            if (unbindListener!=null){
                item?.let { it1 -> unbindListener.unBind(it1) }
            }
         }

    }

    /**
     * 解绑监听
     */
    interface UnbindListener{
        fun unBind(bindMachineBean: BindMachineBean);
    }
}